<?php

namespace App\Models;

class Comment extends BaseModel
{
    protected $table = 'comments';

    protected $fillable = [
        'user_id',
        'user_fid',
        'goods_id',
        'order_id',
        'pid',
        'pic',
        'star',
        'content',
        'status',
    ];

    public function getPicAttribute($value)
    {
        return $value ? explode(',', $value) : [];
    }

    public function setPicAttribute($value)
    {
        $this->attributes['pic'] = $value ? implode(',', $value) : null;
    }

    public function user()
    {
        return $this->hasOne(User::class, 'id', 'user_id')->select('id', 'nickname', 'avatar');
    }

    public function reply()
    {
        return $this->hasOne(Comment::class, 'id', 'pid');
    }
}
